package com.training.admin.dao;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.training.admin.entity.department.Department;
import com.training.admin.entity.project.Project;
import com.training.admin.entity.project.ProjectPhase;
import com.training.admin.entity.project.ProjectPhaseCourse;
import com.training.admin.entity.project.ProjectTrainee;

@Dao("hibernate")
public interface ProjectDataDao {
	
	/**
	 * 
	 * @return
	 */
	@Query("SELECT COUNT(*) FROM Project WHERE disabled = false")
	public int countAll();
	
	/**
	 * 
	 * @param departmentId
	 * @return
	 */
	@Query("SELECT COUNT(*) FROM Project WHERE disabled = false AND department.id =:departmentId")
	public int countByDepartmentId(@Variable("departmentId") Long departmentId);
	
	
	/**
	 * 
	 * @param beginIndex
	 * @param maxResult
	 * @return
	 */
	@Limit
	@Query("FROM Project WHERE disabled = false ORDER BY createTime DESC")
	public List<Project> list(@Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);

	/**
	 * 
	 * @param DepartmentId
	 * @param beginIndex
	 * @param maxResult
	 * @return
	 */
	@Limit
	@Query("FROM Project WHERE disabled = false AND department.id =:departmentId ORDER BY createTime DESC")
	public List<Project> listByDepartmentId(@Variable("departmentId") Long departmentId, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
 	
	/**
	 * 
	 * @param id
	 * @return
	 */
	@Query("FROM ProjectPhase WHERE disabled = false AND project.id =:id")
	public List<ProjectPhase> listByProjectId(@Variable("id") Long id);
	
	/**
	 * 
	 * @param id
	 * @return
	 */
	@Query("FORM Department WHERE disabled = false AND id =:id")
	public List<Department> listDepartmentById(@Variable("id") Long id);
	
	/**
	 * 
	 * @return
	 */
	@Query("FROM ProjectTrainee WHERE disabled = false AND project.id =:id")
	public List<ProjectTrainee> listProjectTraineeByProjectid(@Variable("id") Long id);

	/**
	 * 
	 * @param id
	 * @return
	 */
	@Query("FROM ProjectPhaseCourse WHERE disabled = false AND projectPhase.id in (:ids)")
	public List<ProjectPhaseCourse> listByprojectPhaseId(@Variable("ids") List<Long> ids);


}
